'''
The best parser ever written for .logo files
'''

def load(filename):
	with open(filename, 'rb') as f:
		return [line.replace('\n','') for line in f.readlines() if line != '\n']

def parse(data):
	data = ' '.join(data).split(' ')
	
	command_list = []
	repeat_list = []

	i = 0 
	while i < len(data):
		if data[i] == 'REPEAT': 
			repeat_num = int(data[i+1]) # Grab the number of times to repeat everything
			i += 3 # Set the index to the first command past the '['
			while data[i] != ']':
				repeat_list.append(data[i])
				i += 1
			command_list += repeat_list * repeat_num
			repeat_list = []
			i += 1
		if i < len(data):
			command_list.append(data[i])
		i += 1

	return command_list


if __name__ == '__main__':
	print parse(load('complex.logo'))